﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AppEnvironment.Lib;
using System.Web.UI;

namespace AppEnvironment.Web
{
    public class PageWithPresenter<T> : Page
        where T : Presenter, new()
    {

        private T mPresenter;
        public T Presenter
        {
            get { return mPresenter ?? (mPresenter = App.New<T>()); }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Presenter.ViewInitialized(!IsPostBack);
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Presenter.ViewLoaded(!IsPostBack);
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Presenter.ViewAboutToRender(!IsPostBack);
        }

    }
}
